

$(function(){
    
    var rules = {};

    rules['text']                           = set_rules('text', 'text', 'required|min_length[2]|maxlength[1000]');
    rules['numeric']                        = set_rules('numeric', 'numeric', 'required|number|min_length[1]|maxlength[11]');
    rules['email']                          = set_rules('email', 'email', 'required|valid_email|min_length[1]|maxlength[100]');
    rules['url']                            = set_rules('url', 'url', 'required|valid_url|min_length[1]|max_length[1000]');
    rules['password']                       = set_rules('password', 'password', 'required|min_length[4]|max_length[1000]');
    rules['confirm-password']               = set_rules('confirm-password', 'confirm password', 'required|matches[password-validation]|min_length[1]|max_length[1000]');
    rules['radio-inline-validation']        = set_rules('radio-inline-validation', 'radio', 'required');
    rules['checkbox-inline-validation']     = set_rules('checkbox-inline-validation', 'checkbox', 'required');
    rules['dropdown']                       = set_rules('dropdown-validation', 'dropdown', 'required');
    rules['text-area']                      = set_rules('dropdown-validation', 'dropdown', 'min_length[2]');
    
//    alert( rules['text'].toSource() );
    
    // Validation
    $(".form-validate").validate({
        errorElement: 'small',
        errorClass: 'help-block',
        rules: rules,
        errorPlacement:function(error, element) {
            element.parents('.input-size').append( '<div class="clear-fix"></div>' );
            element.parents('.input-size').append( error);
        },
        highlight: function(label) {
            $(label).closest('.form-group').removeClass('has-error has-success').addClass('has-error');
        },
        success: function(label) {
            label.addClass('valid').closest('.form-group').removeClass('has-error has-success').addClass('has-success');
        }
    });

});